<?php
/*************************************************************/
/*
/*	Lightweight DB class
/*	By: Nathan Adams
/*
/*
/*************************************************************/
class db {
	var $nquries;
	var $link;

	function db($host, $username, $password, $db = "")
	{
		$this->link = mysql_connect($host, $username, $password) or die(mysql_error());
		if ($db != "")
			mysql_select_db($db) or die(mysql_error());
	}
	function select($value, $table, $where="", $order="")
	{
		$ret_q = $this->query("SELECT " . $value . " FROM " . $table . " " . $where . " " . $order);
		$ret = array();
		$i = 0;
		while($ret = mysql_fetch_array($ret_q, MYSQL_NUM))
			foreach($ret as $r)
			{
				$ret1[$i] = $r;
				++$i;
			}
		return $ret1;
	}
	function select2($value, $table, $where="", $order="")
	{
		$ret_q = $this->query("SELECT " . $value . " FROM " . $table . " " . $where . " " . $order);
				$i = 0;
		while($ret = mysql_fetch_array($ret_q, MYSQL_ASSOC))
			foreach($ret as $r)
			{
				$ret1[$i] = $r;
				++$i;
			}
		return $ret1;
	}
	function query($query)
	{
		++$this->nquries;
		$ret =  mysql_query($query) or die(mysql_error());
		return $ret;
	}
	function getNumQuries()
	{
		return $this->nquries;
	}
	function __destruct()
	{
		mysql_close($this->link);
	}
	function outLog($query)
	{
		echo $query;
		echo mysql_error();
	}
	function previous_id($table, $id_column) {
	  if ($table && $id_column) {
	    $result = $this->query("SELECT MAX(".$id_column.") AS maxid FROM ".$table);
	    $stuff = mysql_fetch_assoc($result);
	    return $stuff['maxid'];
	  } else {
	    return false;
	  }
	}
	function logError()
	{
                //log it
	}
}

?>